using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EndUI : MonoBehaviour
{
    [SerializeField] private GameObject endUI;
    [SerializeField] private InputField inputField;

    private void Start() {
        endUI.SetActive(false);
    }

    private void OnEnable() {
        EventHandler.AddListener(Events.EndGame, CallEndUI);
    }

    private void OnDisable() {
        EventHandler.RemoveListener(Events.EndGame);
    }

    private void CallEndUI()
    {
        endUI.SetActive(true);
    }

    public void OnClickMainMenu()
    {
        if(!string.IsNullOrEmpty(inputField.text))
        {
            ScoreManager.Instance.UpdatePlayerName(inputField.text);
            ScoreManager.Instance.SavePlayerScoreData();
            SceneLoader.Instance.LoadMainMenu();
            endUI.SetActive(false);
        }
    }
}
